package com.ruoyi.web.controller.finance;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.finance.domain.AccountsReceivable;
import com.ruoyi.finance.service.IAccountsReceivableService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 应收账款Controller
 * 
 * @author liuyu
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/finance/receivable")
public class AccountsReceivableController extends BaseController
{
    @Autowired
    private IAccountsReceivableService accountsReceivableService;

    /**
     * 查询应收账款列表
     */
    @PreAuthorize("@ss.hasPermi('finance:receivable:list')")
    @GetMapping("/list")
    public TableDataInfo list(AccountsReceivable accountsReceivable)
    {
        startPage();
        List<AccountsReceivable> list = accountsReceivableService.selectAccountsReceivableList(accountsReceivable);
        return getDataTable(list);
    }

    /**
     * 导出应收账款列表
     */
    @PreAuthorize("@ss.hasPermi('finance:receivable:export')")
    @Log(title = "应收账款", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccountsReceivable accountsReceivable)
    {
        List<AccountsReceivable> list = accountsReceivableService.selectAccountsReceivableList(accountsReceivable);
        ExcelUtil<AccountsReceivable> util = new ExcelUtil<AccountsReceivable>(AccountsReceivable.class);
        util.exportExcel(response, list, "应收账款数据");
    }

    /**
     * 获取应收账款详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance:receivable:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(accountsReceivableService.selectAccountsReceivableById(id));
    }

    /**
     * 新增应收账款
     */
    @PreAuthorize("@ss.hasPermi('finance:receivable:add')")
    @Log(title = "应收账款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccountsReceivable accountsReceivable)
    {
        return toAjax(accountsReceivableService.insertAccountsReceivable(accountsReceivable));
    }

    /**
     * 修改应收账款
     */
    @PreAuthorize("@ss.hasPermi('finance:receivable:edit')")
    @Log(title = "应收账款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccountsReceivable accountsReceivable)
    {
        return toAjax(accountsReceivableService.updateAccountsReceivable(accountsReceivable));
    }

}